package com.cy.cykh.app.view.activity

import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.animation.Animation
import android.view.animation.DecelerateInterpolator
import android.view.animation.Interpolator
import android.view.animation.ScaleAnimation
import android.widget.ImageView
import com.cy.cykh.app.cdyapp.R
import com.cy.cykh.app.util.showProgress
import com.cy.cykh.app.view.activity.LoginActivity
import kotlinx.android.synthetic.main.activity_splash.*

/**
 * @author Administrator
 * @FileName
 * @date 2019/1/2 11:32
 */
class SplashActivity :AppCompatActivity() {
    var image: ImageView? = null
    override fun onPostCreate(savedInstanceState: Bundle?) {
        super.onPostCreate(savedInstanceState)
        //某些手机release版本会在点击home键后再点击icon后会再走一遍app启动过程
        if (!isTaskRoot) {
            val intent = intent
            if (intent != null) {
                val action = intent.action
                if (intent.hasCategory(Intent.CATEGORY_LAUNCHER) && Intent.ACTION_MAIN == action) {
                    finish()
                    return
                }
            }
        }
//        // 隐藏标题栏
//        requestWindowFeature(Window.FEATURE_NO_TITLE)
//        // 隐藏状态栏
//        window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
        setContentView(R.layout.activity_splash)
        image=image_logo
        animation()

    }
    private fun animation() {
        //放大动画
        val animation = ScaleAnimation(1.0f, 1.3f, 1.0f, 1.3f,
                Animation.RELATIVE_TO_SELF, 0.5f,
                Animation.RELATIVE_TO_SELF, 0.5f)
        animation.interpolator = DecelerateInterpolator() as Interpolator?
        animation.duration = 1000 * 2
        animation.fillAfter = true

        animation.setAnimationListener(object : Animation.AnimationListener {
            override fun onAnimationStart(animation: Animation) {

            }

            override fun onAnimationEnd(animation: Animation) {
                //动画结束进入MainActivity
                LoginActivity.launch(this@SplashActivity)
                finish()
            }

            override fun onAnimationRepeat(animation: Animation) {

            }
        })
        image?.startAnimation(animation)
    }

     override fun onDestroy() {
        super.onDestroy()
         image = null

    }

}